<?php
/**
 * Object Relational Persistence Mapping Class for table: pha_req_exticket_detail
 *
 * @package	modules.dept_pharmacy.ordo
 * @author	viethd
 * @version $
 * @copyright 2009 LHV Company
 */
class PhaReqExticketDetail extends ORDataObject {

    /**#@+
     * Fields of table: pha_req_exticket_detail mapped to class members
     */
    var $pha_req_exticket_detail_id		= '';
    var $pha_req_exticket_id		= '';
    var $pha_drug_material_id		= '';
    var $quantity		= '';
    var $note		= '';
    /**#@-*/


    /**
     * DB Table
     */
    var $_table = 'pha_req_exticket_detail';

    /**
     * Primary Key
     */
    var $_key = 'pha_req_exticket_detail_id';

    /**
     * Internal Name
     */
    var $_internalName = 'PhaReqExticketDetail';

    /**
     * Handle instantiation
     */
    function __construct() {
        parent::ORDataObject();
    }

    public function listReqExticketDetail($reqExticketId) {
        $ds =& new Datasource_sql();
         
        $sql = array(
                    'cols'  => "pha_req_exticket_detail_id,
                     t.pha_drug_material_id, quantity, proprietary_name, note, enum_unit_import_sell",
                    'from'  => "$this->_table t INNER JOIN pha_drug_material pdm
                                ON (t.pha_req_exticket_id='$reqExticketId' AND t.pha_drug_material_id = pdm.pha_drug_material_id)"
        );
        $ds->setup($this->_db, $sql);
        $result = $ds->toArray();
        return $result;
    }
    
    public function listAprrovedExticketDetail($reqExticketId) {
        $ds =& new Datasource_sql();
         
        $sql = array(
                    'cols'  => "t.pha_req_exticket_detail_id,
                     t.pha_drug_material_id, quantity, proprietary_name, t.note, enum_unit_import_sell, peed.approve_quantity, peed.note app_note",
                    'from'  => "$this->_table t
                                INNER JOIN pha_drug_material pdm ON (t.pha_req_exticket_id='$reqExticketId' AND t.pha_drug_material_id = pdm.pha_drug_material_id) 
                                LEFT JOIN pha_ewh_exticket_detail peed ON (t.pha_req_exticket_detail_id=peed.pha_req_exticket_detail_id)
                                "
        );
        $ds->setup($this->_db, $sql);
        $result = $ds->toArray();
        
        return $result;
    }
    
    public function getReqExticketDetail($reqExticketDetailId) {
        $ds =& new Datasource_sql();
         
        $sql = array(
                    'cols'  => "pha_req_exticket_detail_id,
                     t.pha_drug_material_id, quantity, proprietary_name, note, enum_unit_import_sell, note",
                    'from'  => "$this->_table t INNER JOIN pha_drug_material pdm
                                ON (t.pha_req_exticket_detail_id='$reqExticketDetailId' AND t.pha_drug_material_id = pdm.pha_drug_material_id)"
        );
        $ds->setup($this->_db, $sql);
        $result = $ds->toArray();
        if (empty($result)) {
            return null;
        }
        return $result[0];
    }

}
?>
